package org.testis.testdriver.parser;

import org.testis.testdriver.AtofEnumaration;
import org.testis.testdriver.ITestBuilder;
import java.util.LinkedList;
import org.orm.PersistentException;
import org.testis.orm.refinedclasses.TestCaseRefined;
import org.testis.orm.refinedclasses.TestDesignTreeNode;
import org.testis.orm.refinedclasses.TestDesignTreeRefined.TestDesignTreeParameters;

/**
 *
 * @author barisergun
 */
public class TestDriverTestCaseRefinedParsing extends TestDriverAbstractParsingStrategy {

    public TestDriverTestCaseRefinedParsing(ITestBuilder builder,
            TestDesignTreeNode currentNode) {
        m_builder = builder;
        m_currentNode = currentNode;

        if (m_currentNode.isClone()) {
            m_cloneString = " [clone]";
        }
    }

    @Override
    public void parseCurrentNode() throws PersistentException {
        TestCaseRefined testPart =
                (TestCaseRefined) m_currentNode.getObject();
        m_builder.buildTestPart(String.valueOf(m_currentNode.getId()),
                testPart.getName() + m_cloneString,
                testPart.getReference().getDescription(),
                AtofEnumaration.TestPartType.TestCase,
                String.valueOf(m_currentNode.getParent().getId()));
        m_builder.setTestPartDependency(String.valueOf(m_currentNode.getId()),
                null,
                true);
        Byte successPercentage = m_currentNode.getReference().getParameterByteValue(TestDesignTreeParameters.SuccessPercentage.name());
        Integer invocationCount = m_currentNode.getReference().getParameterIntValue(TestDesignTreeParameters.InvocationCount.name());
        Integer threadPoolSize = m_currentNode.getReference().getParameterIntValue(TestDesignTreeParameters.ThreadPoolSize.name());
        if (threadPoolSize != null) {
            threadPoolSize = 0;
        }
        if (invocationCount == null) {
            invocationCount = 0;
        }
        m_builder.setTestCaseThreading(String.valueOf(m_currentNode.getId()), invocationCount, threadPoolSize);
        if (successPercentage != null) {
            m_builder.setTestCaseSuccessPerc(String.valueOf(m_currentNode.getId()),
                    successPercentage);
        }
        LinkedList<String> condList = getConditionsOfTestPart();

        m_builder.setTestPartConditions(String.valueOf(m_currentNode.getId())
                , condList);
    }
}
